# coding=utf-8
import math
import collections

class Solution:
    def minWindow(self, s, t):
        """
        :type s: str
        :type t: str
        :rtype: str
        """
        map = [0] * 128
        for c in t:
            map[ord(c)] += 1
        counter = len(t)
        begin = 0
        end = 0
        d = 65536
        head = 0
        while end < len(s):
            
            if map[ord(s[end])] > 0:
                counter-=1
            map[ord(s[end])] -= 1
            end += 1
            
            while counter == 0:
                if end - begin < d:
                    head = begin
                    d = end-(head)
                if map[ord(s[begin])] == 0:
                    counter +=1
                map[ord(s[begin])] += 1
                begin += 1
                
        return "" if d==65536 else s[head:head+d]

def main():
    sol = Solution()
    print(sol.minWindow("bbaa", "aba"))


if __name__ == "__main__":
    main()
